<template>
	<img v-if="image" :src="image" alt="" @click="fangda">
</template>

<script>
	import {
		queryBase64
	} from "@/api/mine.js";
	import {
		base64ToPath
	} from "../../utils/base64";

	export default {
		name: "index",
		props: {
			src: {
				type: String,
				default: ''
			},
			big: {
				type: Boolean,
				default: false
			},
			qj: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				image: '/static/images/loading.gif',
				running: true
			}
		},

		watch: {
			/* src(newVal) {
      var param={
        url:this.src,
        userId:localStorage.getItem("userId")
      }
	  console.log(this.src)
      queryBase64(param).then(res=>{
        this.image=res.data
      })
    } */
		},
		destroyed() {
			this.running = false
		},
		mounted() {
			const CONFIG = window.config.common;
			const openSecurity = CONFIG.openSecurity;
			if (openSecurity) {
				if (this.src != null && this.src != '') {
					var param = {
						url: this.src,
						userId: localStorage.getItem("userId")
					}
					this.downloadImage(param)
				}
			} else {
				// this.image='/fileApi/'+this.src
				this.image = this.src
			}
			/* if(this.src.indexOf("http")>-1){
				 this.image=this.src
			}else{
				if(this.src!=null && this.src!=''){
					var param={
					  url:this.src,
					  userId:localStorage.getItem("userId")
					}
					queryBase64(param).then(res=>{
					  this.image=res.data
					})
				}
			} */


		},
		methods: {
			downloadImage(param) {
				queryBase64(param).then(res => {
					if (res && res.data) {
						this.image = res.data
					} else {
						if (this.running) {
							this.downloadImage(param)
						}
					}
				})
			},
			fangda() {


				if (this.big) {
					const CONFIG = window.config.common;
					const openSecurity = CONFIG.openSecurity;
					if (openSecurity) {
						if (this.qj != null && this.qj != '') {
							/*if(this.qj.indexOf('http')>-1){
							  let imgs = [];
							  imgs[0] = this.qj;

							  uni.previewImage({
							    current: 0,
							    urls: imgs
							  });
							}else{
							  var param={
							    url:this.qj,
							    userId:localStorage.getItem("userId")
							  }
							  queryBase64(param).then(res=>{
							    base64ToPath(res.data)
							        .then(path => {
							          let imgs = [];
							          imgs[0] = path;

							          uni.previewImage({
							            current: 0,
							            urls: imgs
							          });
							        })
							        .catch(error => {
							          // 图片加载失败
							        })
							  })
							}*/
							var param = {
								url: this.qj,
								userId: localStorage.getItem("userId")
							}
							queryBase64(param).then(res => {
								base64ToPath(res.data)
									.then(path => {
										let imgs = [];
										imgs[0] = path;

										uni.previewImage({
											current: 0,
											urls: imgs
										});
									})
									.catch(error => {
										// 图片加载失败
									})
							})
						} else {
							base64ToPath(this.image)
								.then(path => {
									let imgs = [];
									imgs[0] = path;

									uni.previewImage({
										current: 0,
										urls: imgs
									});
								})
								.catch(error => {
									// 图片加载失败
								})
						}
					} else {
						let imgs = [];
						// imgs[0] = '/fileApi/' + this.qj;
						imgs[0] = this.qj;

						uni.previewImage({
							current: 0,
							urls: imgs
						});
					}


				}
			}
		}
	}
</script>

<style scoped>

</style>